/**
 * @author:linjiye
 * @date: 2024/01/14
 * @desc: AI原创模块接口定义
 **/

import {createApi} from "@reduxjs/toolkit/query/react";
import useBaseQuery from "@/hooks/useBaseQuery";
import { stringify } from "qs";

export const useExplosiveApi = createApi({
    reducerPath:'useExplosiveApi',
    baseQuery:useBaseQuery('mm'),
    endpoints(build) {
        return {
            // http://192.168.200.122:3200/jeecgboot/mm/aicreation/download_from_url
            downloadFromUrl:build.mutation({
                query:(data:any) => {
                    console.log(data,'----');
                    // 创建一个 FormData 对象
                    const formData = new FormData();
                    // 遍历 data 对象，将其键值对添加到 FormData 中
                    for (const key in data) {
                        if (data.hasOwnProperty(key)) {
                            formData.append(key, data[key]);
                        }
                    }
                    return {
                        url: 'aicreation/download_from_url',
                        method:"post",
                        body:formData,
                        openErrMessage: true
                    }
                },
            }),
            // http://192.168.200.122:3200/jeecgboot/mm/aicreation/recognize?file=recognize%5Cf9773378-a448-44c4-a1c7-e5313f407fe8.mp4

            recognize:build.mutation({
                query:(data:any) => {
                    return {
                        url: 'aicreation/recognize?file='+data.file,
                        method:"post",
                    }
                },
                transformResponse(baseQueryReturnValue, meta, arg) {
                    console.log(baseQueryReturnValue,'00000000000');
                    return baseQueryReturnValue.data;
                },
            }),
        }
    }
});

export const {
    useDownloadFromUrlMutation,
    useRecognizeMutation
} = useExplosiveApi;
